[All] Refactor nvte_get_fused_attn_backend with cudnn-frontend calls#2964
[All] Refactor nvte_get_fused_attn_backend with cudnn-frontend calls#2964cyanguwa wants to merge 40 commits into
Conversation
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
for more information, see https://pre-commit.ci
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
Greptile SummaryThis PR replaces the hand-maintained boolean logic in
Confidence Score: 2/5Not safe to merge as-is: the deprecated wrapper regression silently returns NVTE_No_Backend for all BSHD/SBHD F16 configs, and temporary debug instrumentation with an atexit handler ships unconditionally. The probe-based v2 approach is architecturally sound, but two defects block a clean merge: (1) the deprecated wrapper omits batch_size, causing cuDNN to reject every probe graph and silently breaking all existing callers; (2) graph_debug.h is self-labeled temporary yet registers an atexit handler and atomic counters in every build. transformer_engine/common/fused_attn/fused_attn.cpp (deprecated wrapper batch_size=0 regression), transformer_engine/common/fused_attn/graph_debug.h (unconditional atexit handler in production builds) Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Caller as PyTorch/JAX/C++ Caller
participant v2 as nvte_get_fused_attn_backend_v2
participant pfwd as is_supported_f16_fwd
participant pbwd as is_supported_f16_bwd
participant ifwd as fused_attn_arbitrary_seqlen_fwd_impl
participant ibwd as fused_attn_arbitrary_seqlen_bwd_impl
participant cuDNN as cuDNN Graph Build
Caller->>v2: NVTEFusedAttnConfig
v2->>v2: early dtype/heads/seqlen checks
v2->>pfwd: cfg + handle
pfwd->>ifwd: "cfg with all device ptrs = nullptr"
ifwd->>cuDNN: build fwd graph (batch, s_q, s_kv, h, d)
alt graph builds OK
cuDNN-->>ifwd: compiled graph
ifwd-->>pfwd: workspace_size
pfwd-->>v2: empty string (supported)
else cuDNN rejects
cuDNN-->>ifwd: exception
pfwd-->>v2: error string
v2-->>Caller: NVTE_No_Backend
end
alt is_training and not is_forward
v2->>pbwd: cfg + handle
pbwd->>ibwd: "cfg with all device ptrs = nullptr"
ibwd->>cuDNN: build bwd graph
cuDNN-->>ibwd: result or exception
pbwd-->>v2: empty string or error string
end
v2-->>Caller: NVTE_F16_arbitrary_seqlen or NVTE_No_Backend
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Caller as PyTorch/JAX/C++ Caller
participant v2 as nvte_get_fused_attn_backend_v2
participant pfwd as is_supported_f16_fwd
participant pbwd as is_supported_f16_bwd
participant ifwd as fused_attn_arbitrary_seqlen_fwd_impl
participant ibwd as fused_attn_arbitrary_seqlen_bwd_impl
participant cuDNN as cuDNN Graph Build
Caller->>v2: NVTEFusedAttnConfig
v2->>v2: early dtype/heads/seqlen checks
v2->>pfwd: cfg + handle
pfwd->>ifwd: "cfg with all device ptrs = nullptr"
ifwd->>cuDNN: build fwd graph (batch, s_q, s_kv, h, d)
alt graph builds OK
cuDNN-->>ifwd: compiled graph
ifwd-->>pfwd: workspace_size
pfwd-->>v2: empty string (supported)
else cuDNN rejects
cuDNN-->>ifwd: exception
pfwd-->>v2: error string
v2-->>Caller: NVTE_No_Backend
end
alt is_training and not is_forward
v2->>pbwd: cfg + handle
pbwd->>ibwd: "cfg with all device ptrs = nullptr"
ibwd->>cuDNN: build bwd graph
cuDNN-->>ibwd: result or exception
pbwd-->>v2: empty string or error string
end
v2-->>Caller: NVTE_F16_arbitrary_seqlen or NVTE_No_Backend
Reviews (20): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile |
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
for more information, see https://pre-commit.ci
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
for more information, see https://pre-commit.ci
|
/te-ci L1 |
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
for more information, see https://pre-commit.ci
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
for more information, see https://pre-commit.ci
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
|
There is a limitation for torch.compile dynamic shapes here. If I don't think this is a blocker for this PR, but we need to keep it in mind. |
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
… fwd/bwd, thread bias shapes through in jax Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
57bc228 to
391fe2e
Compare
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
for more information, see https://pre-commit.ci
…cache_key, fix Jax bias Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
…raph_debug, fix bias shape handling Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
f5ba9d5 to
eadd005
Compare
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
| /************************************************************************* | ||
| * Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * | ||
| * See LICENSE for license information. | ||
| ************************************************************************/ | ||
|
|
||
| // ============================================================================ | ||
| // [GRAPH-DEBUG] TEMPORARY DEBUG INSTRUMENTATION -- REMOVE AFTER VERIFICATION. | ||
| // | ||
| // Counts fused-attention cuDNN graph *builds* (cache misses that construct a new | ||
| // graph) vs. *executions* (real forward/backward runs, excluding workspace-sizing | ||
| // probes) to detect redundant graph construction. | ||
| // | ||
| // Enable at runtime with: export NVTE_FUSED_ATTN_GRAPH_DEBUG=1 | ||
| // A running "BUILD" line is printed whenever a new graph is constructed, and a | ||
| // "SUMMARY" line with final totals is printed at process exit. | ||
| // | ||
| // To remove all of this instrumentation later: | ||
| // 1. Delete this file (graph_debug.h). | ||
| // 2. Remove every line tagged with the "[GRAPH-DEBUG]" marker in: | ||
| // - fused_attn_fp8.cu | ||
| // - fused_attn_f16_arbitrary_seqlen.cu | ||
| // ============================================================================ |
There was a problem hiding this comment.
Temporary debug instrumentation shipped in production build
This file is explicitly labeled "TEMPORARY DEBUG INSTRUMENTATION -- REMOVE AFTER VERIFICATION" in its own header comment, yet it is included in this PR. The atexit handler and atomic counters are compiled into every build unconditionally; only the runtime output is gated behind NVTE_FUSED_ATTN_GRAPH_DEBUG. This should be removed before merge or tracked with a follow-up issue — otherwise the instrumentation accumulates permanently in the library.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com>
c2152da to
28f5a8c
Compare
for more information, see https://pre-commit.ci
| transformer_engine::FusedAttnConfig cfg{}; | ||
| cfg.qkv_layout = qkv_layout; | ||
| cfg.bias_type = bias_type; |
There was a problem hiding this comment.
Deprecated wrapper leaves
batch_size=0, breaking all BSHD/SBHD probes
FusedAttnConfig cfg{} zero-initialises batch_size. The old API signature had no such parameter, so the wrapper never sets it. is_supported_f16_fwd then calls derive() (which bucketed_batch_size inherits from zero) and calls into fused_attn_arbitrary_seqlen_fwd_impl with b = 0. cuDNN rejects a graph whose batch tensor has size 0, throwing an exception. The catch block returns a non-empty error string, and nvte_get_fused_attn_backend_v2 returns NVTE_No_Backend for every BSHD/SBHD F16 configuration — a silent regression for every existing caller of the deprecated entry-point. A safe fallback is to seed cfg.batch_size = 1 since the probe only needs a structurally-valid (non-zero) dimension to succeed.
| transformer_engine::FusedAttnConfig cfg{}; | |
| cfg.qkv_layout = qkv_layout; | |
| cfg.bias_type = bias_type; | |
| transformer_engine::FusedAttnConfig cfg{}; | |
| cfg.batch_size = 1; // probe needs a non-zero batch; old API had no batch_size parameter | |
| cfg.qkv_layout = qkv_layout; | |
| cfg.bias_type = bias_type; |
Description
This PR replaces the hand-maintained backend selection logic in
nvte_get_fused_attn_backendwith cudnn-frontend's production-grade support checks.nvte_get_fused_attn_backendcall.Type of change
Changes
See Description.
Checklist: